]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
screenshot: Restrict callers
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 16 Jun 2021 20:11:50 +0000 (22:11 +0200)
committerMarge Bot <marge-bot@gnome.org>
Fri, 3 Sep 2021 21:34:58 +0000 (21:34 +0000)
The shell D-Bus API was always meant as a private API for core
components, so enforce that by limiting caller to a list of
allowed well-known names.

Applications that want to request a screenshot can use the corresponding
desktop portal.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3943

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1970>

js/ui/screenshot.js

index 81ab516b171483c8f8300e58bea72b753218c500..bf537b7d6d083326d3f8cce2449a57821c20cc73 100644 (file)
@@ -15,6 +15,7 @@ Gio._promisify(Shell.Screenshot.prototype,
     'screenshot_area', 'screenshot_area_finish');
 
 const { loadInterfaceXML } = imports.misc.fileUtils;
+const { DBusSenderChecker } = imports.misc.util;
 
 const ScreenshotIface = loadInterfaceXML('org.gnome.Shell.Screenshot');
 
@@ -24,6 +25,12 @@ var ScreenshotService = class {
         this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell/Screenshot');
 
         this._screenShooter = new Map();
+        this._senderChecker = new DBusSenderChecker([
+            'org.gnome.SettingsDaemon.MediaKeys',
+            'org.freedesktop.impl.portal.desktop.gtk',
+            'org.freedesktop.impl.portal.desktop.gnome',
+            'org.gnome.Screenshot',
+        ]);
 
         this._lockdownSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.lockdown' });
 
@@ -46,6 +53,13 @@ var ScreenshotService = class {
                 Gio.IOErrorEnum, Gio.IOErrorEnum.PERMISSION_DENIED,
                 'Saving to disk is disabled');
             return null;
+        } else {
+            try {
+                this._senderChecker.checkInvocation(invocation);
+            } catch (e) {
+                invocation.return_gerror(e);
+                return null;
+            }
         }
 
         let shooter = new Shell.Screenshot();
@@ -254,6 +268,13 @@ var ScreenshotService = class {
     }
 
     async SelectAreaAsync(params, invocation) {
+        try {
+            this._senderChecker.checkInvocation(invocation);
+        } catch (e) {
+            invocation.return_gerror(e);
+            return;
+        }
+
         let selectArea = new SelectArea();
         try {
             let areaRectangle = await selectArea.selectAsync();
@@ -269,6 +290,13 @@ var ScreenshotService = class {
     }
 
     FlashAreaAsync(params, invocation) {
+        try {
+            this._senderChecker.checkInvocation(invocation);
+        } catch (e) {
+            invocation.return_gerror(e);
+            return;
+        }
+
         let [x, y, width, height] = params;
         [x, y, width, height] = this._scaleArea(x, y, width, height);
         if (!this._checkArea(x, y, width, height)) {